package mc

import (
	"gitee.com/dreamwood/ez-go/db/mgo"
)

const (
	DepartmentEventNew           = "erp.DepartmentNew"
	DepartmentEventBeforeCreate  = "erp.DepartmentBeforeCreate"
	DepartmentEventBeforeUpdate  = "erp.DepartmentBeforeUpdate"
	DepartmentEventBeforeSave    = "erp.DepartmentBeforeCreate erp.DepartmentBeforeUpdate"
	DepartmentEventAfterCreate   = "erp.DepartmentAfterCreate"
	DepartmentEventAfterUpdate   = "erp.DepartmentAfterUpdate"
	DepartmentEventAfterSave     = "erp.DepartmentAfterCreate erp.DepartmentAfterUpdate"
	DepartmentEventDelete        = "erp.DepartmentDelete"
	DepartmentAccessControlEvent = "erp.DepartmentAccessControl"
)

func GetDepartmentConfig() *mgo.DocConfig {
	return Department_Config
}

var Department_Config *mgo.DocConfig

func init() {
	Department_Config = NewDepartmentConfig()
}
func NewDepartmentConfig() *mgo.DocConfig {
	return &mgo.DocConfig{
		ContainerKey: "erp.Department",
		Fields: []string{
			"name", "sort", "l", "r", "level", "link", "parent", "children",
		},
		RelationFields: []string{
			"parent", "children",
		},
		RelationConfigs: map[string]*mgo.DocRelation{
			"parent": {
				Config:     GetDepartmentConfig,
				DocName:    "Department",
				JoinType:   "O",
				KeyInside:  "parentId",
				KeyOutSide: "id",
			},
			"children": {
				Config:     GetDepartmentConfig,
				DocName:    "Department",
				JoinType:   "M",
				KeyInside:  "id",
				KeyOutSide: "parentId",
			},
		},
		FieldFilter: map[string]*mgo.DocFieldFilter{
			"default": {
				Select: []string{},
				Omit:   []string{},
			},
		},
	}
}
